﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.Web.User;
using PowerCreator.LMS.Web.Task;
using PowerCreator.LMS.Task.Entity;
using PowerCreator.LMS.ViewQuery;
using PowerCreator.LMS.Common.Utils;

public partial class sysadmin_TaskManager_AddTask : System.Web.UI.Page
{
    protected PowerCreator.LMS.Web.Config.WebConfig config = new PowerCreator.LMS.Web.Config.WebConfig();
    TaskClassRoomManag objTaskClassRoomManag = new TaskClassRoomManag();
    EvaluateManag objEvaluateManag = new EvaluateManag();
    TaskManag objTaskManag = new TaskManag();
    User objUser = new User();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            PageLoad();
        }
    }
    public void PageLoad()
    {
        DataTable dtTaskClassRoom = objTaskClassRoomManag.Query("");
        dpdlsTaskClassRoomt.DataSource = dtTaskClassRoom;
        dpdlsTaskClassRoomt.DataTextField = "TaskCrName";
        dpdlsTaskClassRoomt.DataValueField = "TaskCrID";
        dpdlsTaskClassRoomt.DataBind();

        DataTable dtTaskEvaluate = objEvaluateManag.Query("");
        dpdlstTaskEvaluateName.DataSource = dtTaskEvaluate;
        dpdlstTaskEvaluateName.DataTextField = "EvateName";
        dpdlstTaskEvaluateName.DataValueField = "EvateID";
        dpdlstTaskEvaluateName.DataBind();

        DataTable dtTaskTeacher = objUser.QueryTeacher("",int.MaxValue,int.MaxValue);
        dpdlstTaskTeacherID.DataSource = dtTaskTeacher;
        dpdlstTaskTeacherID.DataTextField = "TeacherName";
        dpdlstTaskTeacherID.DataValueField = "FKTeacherUserId";
        dpdlstTaskTeacherID.DataBind();

    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
    	string strErr="";
		if(this.txtTaskName.Text =="")
		{
			strErr+="TaskName不能为空！\\n";	
		}
        if (!TimeUtils.IsDateTime(txtTaskStartTime.Text))
        {
            strErr += "TaskStartTime不是时间格式！\\n";
        }
        if (!TimeUtils.IsDateTime(txtTaskEndTime.Text))
        {
            strErr += "TaskEndTime不是时间格式！\\n";
        }
        if(strErr!="")
		{
			Script.Alert(this,"msg",strErr);
			return;
		}
		string TaskName=this.txtTaskName.Text;
		int TaskTrainingDays=0;
		DateTime TaskStartTime=DateTime.Parse(this.txtTaskStartTime.Text);
		DateTime TaskEndTime=DateTime.Parse(this.txtTaskEndTime.Text);
		int TaskTimeType=1;
		int TaskUserCount=0;
		int TaskAuditState=0;
		int TaskAppraiseType=int.Parse(dpdlstTaskAppraiseType.SelectedValue);
		int FKTaskEvaluateID=int.Parse(dpdlstTaskEvaluateName.SelectedValue);
		string FKTaskResourseID="";
		string TaskRemark=this.txtTaskRemark.Text;
		int FKTaskTeacherID=int.Parse(dpdlstTaskTeacherID.SelectedValue);
		int FKTaskClassRoomID=int.Parse(dpdlsTaskClassRoomt.SelectedValue);
		DateTime TaskCreateTime=DateTime.Now;
		int FKTaskCreateID=10000;

        VOTask model = new VOTask();
		model.TaskName=TaskName;
		model.TaskTrainingDays=TaskTrainingDays;
		model.TaskStartTime=TaskStartTime;
		model.TaskEndTime=TaskEndTime;
		model.TaskTimeType=TaskTimeType;
		model.TaskUserCount=TaskUserCount;
		model.TaskAuditState=TaskAuditState;
		model.TaskAppraiseType=TaskAppraiseType;
		model.FKTaskEvaluateID=FKTaskEvaluateID;
		model.FKTaskResourseID=FKTaskResourseID;
		model.TaskRemark=TaskRemark;
		model.FKTaskTeacherID=FKTaskTeacherID;
		model.FKTaskClassRoomID=FKTaskClassRoomID;
		model.TaskCreateTime=TaskCreateTime;
		model.FKTaskCreateID=FKTaskCreateID;
        objTaskManag.AddNew(model);
        Script.RedirectURL("TaskManager.aspx");
    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
        Script.RedirectURL("TaskManager.aspx");
    }
    protected void dpdlstTaskAppraiseType_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (dpdlstTaskAppraiseType.SelectedValue == "2")
        {
            dpdlstTaskEvaluateName.Visible = true;
        }
        else
        {
            dpdlstTaskEvaluateName.Visible = false;
        }
    }
}
